********************************************
***************** Value-added Production Function *************
********************************************
use "$working/results/thetas_R_kl_all", clear
gen spec = 1
append using "$working/results/thetas_R_kl_3lags_all"
replace spec = 2 if missing(spec)

append using "$working/results/thetas_Q_kl_all"
replace spec = 3 if missing(spec)
append using "$working/results/thetas_CS_kl_nic4_all"
replace spec = 4 if missing(spec)
append using "$working/results/thetas_CS_kl_year_nic2_all"
replace spec = 5 if missing(spec)

keep theta_l_hat_q_mean theta_l_hat_q_sd theta_k_hat_q_mean theta_k_hat_q_sd rts rts_se Observations spec
order theta_l_hat_q_mean theta_l_hat_q_sd theta_k_hat_q_mean theta_k_hat_q_sd rts rts_se
xpose, clear varname format(%9.3g)
rename v1 R_kl_all
rename v2 R_kl_3lags_all
rename v3 thetas_Q_kl_all
rename v4 thetas_CS_kl_nic4_all
rename v5 thetas_CS_kl_year_nic2_all

drop if _varname == "spec"
foreach v in  R_kl_all  R_kl_3lags_all thetas_Q_kl_all thetas_CS_kl_nic4_all thetas_CS_kl_year_nic2_all {
	tostring `v', replace format(%9.3g) force
	replace `v' = "(" + `v' + ")" if _varname == "rts_se"
	replace `v' = "[" + `v' + "]" if _varname == "theta_l_hat_q_sd"
	replace `v' = "[" + `v' + "]" if _varname == "theta_k_hat_q_sd"
	replace `v' = "" if `v' == "[.]" | `v' == "." 
}
foreach v in rts_se theta_l_hat_q_sd theta_k_hat_q_sd {
	replace _varname = "" if _varname == "`v'"
}
replace _varname =  `"\(\theta_l^q\)"' if _varname == "theta_l_hat_q_mean"
replace _varname =  `"\(\theta_k^q\)"' if _varname == "theta_k_hat_q_mean"
replace _varname = "RTS" if _varname == "rts"
rename _varname spec

order spec R_kl_all  R_kl_3lags_all thetas_Q_kl_all thetas_CS_kl_nic4_all thetas_CS_kl_year_nic2_all
la var spec ""
texsave  spec R_kl_all  R_kl_3lags_all thetas_Q_kl_all thetas_CS_kl_nic4_all thetas_CS_kl_year_nic2_all using "$tables/output_elasticities_sva.tex", ///
	footnote("Notes: Reports the average output elasticities for labor and capital for the entire sample used in estimation. See Appendix \ref{Appendix: Heterogeneity} for specification details, and Appendix \ref{App: EstDet} for further details on the exact estimation procedures. Standard deviations are in brackets [.], and standard errors (e.g. on estimated returns to scale) are shown with parentheses (.).") ///
	title("Output elasticities (value-added specificaitons)") ///
	nofix replace location(h)  varlab marker(tab:output_elasticities_sva) frag ///
	autonumber width(\textwidth) hlines(6)


********************************************
***************** Gross Output Production Function *************
********************************************
use "$working/results/thetas_Q_klme_all", clear
gen spec = 1
append using "$working/results/thetas_Q_klme_2lags_all"
replace spec = 2 if missing(spec)
append using "$working/results/thetas_CS_klme_OPF_all"
replace spec = 3 if missing(spec)
append using "$working/results/thetas_CS_klme_nic2_all"
replace spec = 4 if missing(spec)
append using "$working/results/thetas_CS_klme_nic4_all"
replace spec = 5 if missing(spec)
append using "$working/results/thetas_CS_klme_year_all"
replace spec = 6 if missing(spec)
append using "$working/results/thetas_CS_klme_year_nic2_all"
replace spec = 7 if missing(spec)
append using "$working/results/thetas_Q_klm_all"
replace spec = 8 if missing(spec)


keep theta_l_hat_q_mean theta_l_hat_q_sd theta_k_hat_q_mean theta_k_hat_q_sd theta_m_hat_q_mean theta_m_hat_q_sd theta_e_hat_q_mean theta_e_hat_q_sd rts rts_se Observations spec
order theta_l_hat_q_mean theta_l_hat_q_sd theta_k_hat_q_mean theta_k_hat_q_sd theta_m_hat_q_mean theta_m_hat_q_sd theta_e_hat_q_mean theta_e_hat_q_sd rts rts_se
xpose, clear varname format(%9.3g)
rename v1 thetas_Q_klme_all
rename v2 thetas_Q_klme_2lags_all
rename v3 thetas_CS_klme_OPF_all
rename v4 thetas_CS_klme_nic2_all
rename v5 thetas_CS_klme_nic4_all
rename v6 thetas_CS_klme_year_all
rename v7 thetas_CS_klme_year_nic2_all
rename v8 thetas_Q_klm_all

drop if _varname == "spec"
foreach v in  thetas_Q_klme_all thetas_Q_klme_2lags_all thetas_CS_klme_OPF_all thetas_CS_klme_nic2_all thetas_CS_klme_nic4_all thetas_CS_klme_year_all thetas_CS_klme_year_nic2_all thetas_Q_klm_all {
	tostring `v', replace format(%9.3g) force
	replace `v' = "(" + `v' + ")" if _varname == "rts_se"
	replace `v' = "[" + `v' + "]" if _varname == "theta_l_hat_q_sd"
	replace `v' = "[" + `v' + "]" if _varname == "theta_k_hat_q_sd"
	replace `v' = "[" + `v' + "]" if _varname == "theta_m_hat_q_sd"
	replace `v' = "[" + `v' + "]" if _varname == "theta_e_hat_q_sd"
	replace `v' = "" if `v' == "[.]" | `v' == "." 
}
foreach v in rts_se theta_l_hat_q_sd theta_k_hat_q_sd theta_m_hat_q_sd theta_e_hat_q_sd {
	replace _varname = "" if _varname == "`v'"
}
replace _varname =  `"\(\theta_l^q\)"' if _varname == "theta_l_hat_q_mean"
replace _varname =  `"\(\theta_k^q\)"' if _varname == "theta_k_hat_q_mean"
replace _varname =  `"\(\theta_m^q\)"' if _varname == "theta_m_hat_q_mean"
replace _varname =  `"\(\theta_e^q\)"' if _varname == "theta_e_hat_q_mean"
replace _varname = "RTS" if _varname == "rts"
rename _varname spec

order spec thetas_Q_klme_all thetas_Q_klme_2lags_all thetas_CS_klme_OPF_all thetas_CS_klme_nic2_all thetas_CS_klme_nic4_all thetas_CS_klme_year_all thetas_CS_klme_year_nic2_all thetas_Q_klm_all
la var spec ""
texsave  spec thetas_Q_klme_all thetas_Q_klme_2lags_all thetas_CS_klme_nic4_all thetas_CS_klme_year_nic2_all thetas_Q_klm_all  using "$tables/output_elasticities_go.tex", ///
	footnote("Notes: Reports the average output elasticities for labor, capital, materials, and energy, for the entire sample used in estimation. See Appendix \ref{Appendix: Heterogeneity} for specification details, and Appendix \ref{App: EstDet} for further details on the exact estimation procedures. Standard deviations are in brackets [.], and standard errors (e.g. on estimated returns to scale) are shown with parentheses (.).") ///
	title("Output elasticities (gross-output specificaitons)") ///
	nofix replace location(h)  varlab marker(tab:output_elasticities_go) frag ///
	autonumber width(\textwidth) hlines(10)
